﻿<%@ Import Namespace="Ornament.MemberShip" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="OrgEditorView.ascx.cs"
    Inherits="Admin_MemberAdmin_Controls_OrgEditorView" %>
<%@ Register Assembly="Microsoft.Practices.Web.UI.WebControls" Namespace="Microsoft.Practices.Web.UI.WebControls"
    TagPrefix="pp" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ Register Src="OrgAssign.ascx" TagName="OrgAssign" TagPrefix="uc1" %>
<%@ Register Src="~/Admin/Member/Controls/RoleAssign.ascx" TagName="RoleAssign" TagPrefix="uc1" %>
<style type="text/css">
    .orgTreeView
    {
        width: 100%;
        float: left;
    }
    .orgTreeView .content
    {
        margin-left: 400px;
    }
    .editPanel
    {
        padding: .5em .5em .5em .5em;
        float: left;
        width: 380px;
        margin-left: -100%;
    }
</style>

<script language="javascript" type="text/javascript">
    function confirmDelete() {
        return confirm("是否删除当前的组织？选择'是'会删除这个组织及它的子组织");
    }
    var selectedId;
    var selectedText;
    function SelectedParent(id, text) {
        selectedId = id;
        selectedText = text;
    }

    $(document).ready(function() {
        init();
        $("#SelecteParentPanel").dialog({
            autoOpen: false,
            width: 400,
            resizable: true,
            buttons: {
                "确认": function() {
                    $("#<%=orgFormView.ClientID%>_selectedParent").text(selectedText);
                    $("#<%=orgFormView.ClientID%>_parentOrgCodeHiddenBox").val(selectedId);
                    $(this).dialog("close");
                },
                "取消": function() {
                    $(this).dialog("close");
                }
            }
        });
    });

    function init() {
        $("#<%=orgFormView.ClientID%>_selectedParent").click(function() {
            $("#SelecteParentPanel").dialog("open");
        });
    }
  
</script>

<div>
    <asp:Button ID="AddImageButton" runat="server" CssClass="inputIcon orgAdd" OnClick="addNewOrg"
        CausesValidation="false" />
    <asp:Button ID="DeleteImageButton" runat="server" CssClass="inputIcon orgDelete"
        OnClick="removeNewOrg" CausesValidation="false" OnClientClick="return confirmDelete()" />
</div>
<div class="orgTreeView">
    <div class="content ui-widget ui-widget-content ui-corner-all">
        <%--  <asp:ImageButton runat="server" ImageUrl="~/images/control_start.png" OnClick="LevelUpImageButton_Click" />
    <asp:ImageButton ID="LevelDownImageButton" runat="server" ImageUrl="~/images/control_end.png"
        OnClick="LevelDownImageButton_Click" />--%>
        <asp:TreeView ID="treeView1" runat="server" OnSelectedNodeChanged="OnMenuItemClick"
            ShowLines="True">
            <Nodes>
                <asp:TreeNode Text="组织单元" Value="root" Selected="true"></asp:TreeNode>
            </Nodes>
        </asp:TreeView>
    </div>
</div>
<div class="editPanel ui-widget ui-widget-content ui-corner-all">
    <pp:ObjectContainerDataSource ID="orgForViewDataSource" runat="server" DataObjectTypeName="Ornament.MemberShip.Org"
        OnCreating="dataSourceCreateObject" OnSelecting="dataSourceGetCurrentOrg" OnUpdated="OrgUpdated"
        OnInserted="OrgInserted" />
    <asp:FormView ID="orgFormView" runat="server" DataKeyNames="Id" DefaultMode="Insert"
        DataSourceID="orgForViewDataSource">
        <EditItemTemplate>
            <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="确定" CssClass="iconButton accept" />
            &nbsp;<asp:Button ID="UpdateCancelButton" runat="server" CausesValidation="False"
                CommandName="Cancel" Text="取消" CssClass="iconButton cancel" />
            <p>
                <asp:Label ID="Label1" runat="server" Text="所属父单元:" AssociatedControlID="selectedParent"></asp:Label>
                <a runat="server" id="selectedParent">
                    <%#Eval("Parent")==null?"组织单元":Eval("Parent.Name")%></a>
                <input type="hidden" id="parentOrgCodeHiddenBox" runat="server" value='<%#Eval("Parent")==null?"":((Member)Eval("Parent")).Id.ToString() %>' />
            </p>
            <p>
                <asp:Label ID="Label2" runat="server" Text="名称:" AssociatedControlID="NameTextBox"></asp:Label>
                <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                <asp:RequiredFieldValidator ID="NameTextBoxValidate" runat="server" ControlToValidate="NameTextBox"></asp:RequiredFieldValidator>
            </p>
            <p>
                <asp:Label ID="Label3" runat="server" Text="备注:" AssociatedControlID="CommentTextBox"></asp:Label>
                <asp:TextBox ID="CommentTextBox" runat="server" Text='<%# Bind("Comment") %>'></asp:TextBox>
            </p>
        </EditItemTemplate>
        <InsertItemTemplate>
            <asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                CssClass="iconButton accept" Text="添加" />
            &nbsp;<asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False"
                CommandName="Cancel" Text="取消" CssClass="iconButton cancel" />
            <p>
                <asp:Label ID="Label1" runat="server" Text="所属父单元:" AssociatedControlID="selectedParent"></asp:Label>
                <a runat="server" id="selectedParent">选择父组织</a>
                <input type="hidden" id="parentOrgCodeHiddenBox" runat="server" />
            </p>
            <p>
                <asp:Label ID="Label2" runat="server" Text="名称:" AssociatedControlID="NameTextBox"></asp:Label>
                <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                <asp:RequiredFieldValidator ID="NameTextBoxValidate" runat="server" ControlToValidate="NameTextBox"></asp:RequiredFieldValidator>
            </p>
            <p>
                <asp:Label ID="Label4" runat="server" Text=" 备注:" AssociatedControlID="CommentTextBox"></asp:Label>
                <asp:TextBox ID="CommentTextBox" runat="server" Text='<%# Bind("Comment") %>' />
            </p>
        </InsertItemTemplate>
    </asp:FormView>
    <p>
        &nbsp;<uc1:RoleAssign ID="RoleAssign1" runat="server" />
</div>
<div id="SelecteParentPanel" style="display: none" title="选择父组织单元">
    <uc1:OrgAssign ID="orgAssign1" runat="server" />
</div>
